package com.zzzy.doc.service.mydoc;

import com.zzzy.common.util.AssertUtil;
import com.zzzy.doc.common.enums.DocStatusEnum;
import com.zzzy.doc.dao.entity.Document;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
public class MyDocCompleteService extends MyDocService {

    @Transactional
    public void complete(Long id) {
        Document document = getDocByIdForUpdate(id);
        AssertUtil.isEquals(DocStatusEnum.COMPLETE.getValue(), document.getStatus(), "公文状态错误，无法进入归档");
        docAdviceService.addAdvice(id, "办结完毕进入归档");

        document.setStatus(DocStatusEnum.ARCHIVED.getValue());
        document.setUpdateTime(LocalDateTime.now());
        baseMapper.updateById(document);
    }
}
